<!--
  // Creation History
  // --------------------------------------------------------------
  //	Company:			HTHK
  //	NAME:				TimeSheetView.jsp
  //	TITLE:				TimeSheet View
  //	FUNCTION:			view TimeSheet by selecting some conditions.
  //	BY:					Jet Tao
  //	DATE:				10/12/2003
  // UPDATE BY:			Beyes Xia
  //	UPDATE DATE:			2004-1-10 13:59
  // LAST UPDATE DATE:		2004-1-12 17:27
  // --------------------------------------------------------------
-->
<%@ include file="../tssheader.jsp" %>
<%@ page import="tss.timesheet.*" %>
<%@ page import="tss.options.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<html>
<%
	Vector time_sheet=(Vector)request.getAttribute("TimeSheet");
	String staff_no=(String)request.getAttribute("StaffNo");
//****** Add By Beyes Xia
	String staff_name=(String)request.getAttribute("StaffName");
//******
	String position=(String)request.getAttribute("Grade");
	//the startdate usually is sunday.
	String start_date=(String)request.getAttribute("StartDate");
	//decide the button "Last Week" is "disable" or not?
	String last_flag=(String)request.getAttribute("last_flag");
	//decide the button "Next Week" is "disable" or not?
	String next_flag=(String)request.getAttribute("next_flag");
	String[] a_week=(String[])request.getAttribute("AWeek");
	//format the number.
	ChangeNum chgNum=new ChangeNum();
	//count the total hours.
	float[] total_hours=new float[7];
	for(int i=0;i<total_hours.length;i++)
	{
		total_hours[i]=0;
	}
    SimpleDateFormat sdf1 = new SimpleDateFormat("dd MMM yyyy",Locale.US);
    SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd",Locale.US);
	for(int i=0;i<a_week.length;i++)
	{
		a_week[i]=sdf1.format(sdf2.parse(a_week[i]));
	}
%>
<script language="JavaScript1.1">
function thisweek()
{
   var today = new Date();
   month=(today.getMonth()+1>9)?(today.getMonth()+1):"0"+(today.getMonth()+1);
   date=(today.getDate()>9)?today.getDate():("0"+today.getDate());
   fm.selected_date.value=today.getYear()+"-"+month+"-"+date;
   fm.which_week.value=1;
	fm.submit();
}
function lastweek()
{
   fm.which_week.value=0;
	fm.submit();
}
function nextweek()
{
   fm.which_week.value=2;
	fm.submit();
}
function init()
{
	fm.last_week.disabled=<%=last_flag%>;
	fm.next_week.disabled=<%=next_flag%>;
}
</script>
<body onload='init()'>
<h2>Time Sheet View</h2>
<form id=fm method=post action='<%=contextPath%>/servlet/tss.timesheet.TimeSheetSearch' >

<input type=hidden name='selected_date' value=<%=start_date%>>
<input type=hidden name='which_week'>


<table>
<tr>
<td>Staff No.</td>
<td><input type=text name='staff_name_option' value='<%=staff_no%>' class=read readonly ></td>
<!-- Add By Beyes Xia -->
<td>&nbsp;Staff Name</td>
<td><input type=text name='staff_name' value='<%=staff_name%>' class=read readonly ></td>
</tr>
<tr>
<!-- ---------------- -->
<td>Position</td>
<td><input type=text name='position' value='<%=position%>' class=read readonly ></td>
<td>&nbsp;Start Date</td>
<td><input type=text value='<%=start_date%>' class=read readonly ></td>
</tr>
</table>
<p>
<table cols=2 border=1 >
<thead>
<td nowrap style='WIDTH:22%'><b><br><br>Project</b></td>
<td nowrap style='WIDTH:22%'><b><br><br>Job</b></td>
<!--	Add By Beyes Xia	-->
<!--	<td nowrap style='WIDTH:10%'><b><br><br>Over Time</b></td>		-->
<!-- ----------------	-->
<td nowrap style='WIDTH:8%'><b>Sun<br><%=a_week[0].substring(3,6)%><br><%=a_week[0].substring(0,2)%></b></td>
<td nowrap style='WIDTH:8%'><b>Mon<br><%=a_week[1].substring(3,6)%><br><%=a_week[1].substring(0,2)%></b></td>
<td nowrap style='WIDTH:8%'><b>Tue<br><%=a_week[2].substring(3,6)%><br><%=a_week[2].substring(0,2)%></b></td>
<td nowrap style='WIDTH:8%'><b>Wed<br><%=a_week[3].substring(3,6)%><br><%=a_week[3].substring(0,2)%></b></td>
<td nowrap style='WIDTH:8%'><b>Thu<br><%=a_week[4].substring(3,6)%><br><%=a_week[4].substring(0,2)%></b></td>
<td nowrap style='WIDTH:8%'><b>Fri<br><%=a_week[5].substring(3,6)%><br><%=a_week[5].substring(0,2)%></b></td>
<td nowrap style='WIDTH:8%'><b>Sat<br><%=a_week[6].substring(3,6)%><br><%=a_week[6].substring(0,2)%></b></td>
</thead>
<%
	if(time_sheet!=null)
	{
		int size=time_sheet.size();
		for(int i=0;i<size;i++)
		{
			String[] time_sheet_str=(String[])time_sheet.get(i);
			total_hours[0]+=(time_sheet_str[2].equals("")?0:Float.parseFloat(time_sheet_str[2]));
			total_hours[1]+=(time_sheet_str[3].equals("")?0:Float.parseFloat(time_sheet_str[3]));
			total_hours[2]+=(time_sheet_str[4].equals("")?0:Float.parseFloat(time_sheet_str[4]));
			total_hours[3]+=(time_sheet_str[5].equals("")?0:Float.parseFloat(time_sheet_str[5]));
			total_hours[4]+=(time_sheet_str[6].equals("")?0:Float.parseFloat(time_sheet_str[6]));
			total_hours[5]+=(time_sheet_str[7].equals("")?0:Float.parseFloat(time_sheet_str[7]));
			total_hours[6]+=(time_sheet_str[8].equals("")?0:Float.parseFloat(time_sheet_str[8]));
//		  System.out.println("in jsp:"+time_sheet_str[2]+"-"+time_sheet_str[3]+"-"+time_sheet_str[4]+"-"+time_sheet_str[5]+"-"+time_sheet_str[6]+"-"+time_sheet_str[7]+"-"+time_sheet_str[8]);
%>
<tr>
<td><%=time_sheet_str[0]%></td>
<td><%=time_sheet_str[1]%></td>
<!-- Add By Beyes Xia -->
<!--	<td align=center><%=time_sheet_str[9]%><td>		-->
<!-- ---------------- -->
<%if(time_sheet_str[2].equals("")){%>
<td>&nbsp;</td>
<%}else{%>
<td align=right><%=chgNum.getFixNum(time_sheet_str[2],2)%></td>
<%}%>

<%if(time_sheet_str[3].equals("")){%>
<td>&nbsp;</td>
<%}else{%>
<td align=right><%=chgNum.getFixNum(time_sheet_str[3],2)%></td>
<%}%>

<%if(time_sheet_str[4].equals("")){%>
<td>&nbsp;</td>
<%}else{%>
<td align=right><%=chgNum.getFixNum(time_sheet_str[4],2)%></td>
<%}%>

<%if(time_sheet_str[5].equals("")){%>
<td>&nbsp;</td>
<%}else{%>
<td align=right><%=chgNum.getFixNum(time_sheet_str[5],2)%></td>
<%}%>

<%if(time_sheet_str[6].equals("")){%>
<td>&nbsp;</td>
<%}else{%>
<td align=right><%=chgNum.getFixNum(time_sheet_str[6],2)%></td>
<%}%>

<%if(time_sheet_str[7].equals("")){%>
<td>&nbsp;</td>
<%}else{%>
<td align=right><%=chgNum.getFixNum(time_sheet_str[7],2)%></td>
<%}%>

<%if(time_sheet_str[8].equals("")){%>
<td>&nbsp;</td>
<%}else{%>
<td align=right><%=chgNum.getFixNum(time_sheet_str[8],2)%></td>
<%}%>
</tr>
<%
		}
	}
%>
<tr>
<td colspan=2>Total(hours)</td>
<td align=right><%=chgNum.getFixNum(String.valueOf(total_hours[0]),2)%></td>
<td align=right><%=chgNum.getFixNum(String.valueOf(total_hours[1]),2)%></td>
<td align=right><%=chgNum.getFixNum(String.valueOf(total_hours[2]),2)%></td>
<td align=right><%=chgNum.getFixNum(String.valueOf(total_hours[3]),2)%></td>
<td align=right><%=chgNum.getFixNum(String.valueOf(total_hours[4]),2)%></td>
<td align=right><%=chgNum.getFixNum(String.valueOf(total_hours[5]),2)%></td>
<td align=right><%=chgNum.getFixNum(String.valueOf(total_hours[6]),2)%></td>
</tr>

</table>
<hr>
<p>
  <INPUT type=button name='last_week' value='Last Week' onclick='lastweek()'>
  <INPUT type=button name='next_week' value='Next Week' onclick='nextweek()'>
  <INPUT type=button name='this_week' value='This Week' onclick='thisweek()'>
<INPUT type=button value=Back onclick="location.href= '<%=contextPath%>/tss/timesheet/TimeSheetSearch.jsp'">
</p>
</form>
<%@ include file="../tssfooter.jsp" %>
</body>
</html>
